package com.meihua.shellapp.activity.set;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.meihua.shellapp.R;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.BaseBean;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.utils.MyStringCallBack;
import com.meihua.shellapp.utils.ToastUtils;
import com.meihua.shellapp.utils.URL;

import butterknife.Bind;

/**
 * 作者：lc on 2017/10/19.
 * 邮箱：lc0607live@163.com
 */

public class SetNewPayPwdActivity extends BaseActivity {

    @Bind(R.id.iv_top_left)
    ImageView iv_top_left;//返回
    @Bind(R.id.tv_title)
    TextView tv_title;//标题
    @Bind(R.id.bt_submit)
    Button bt_submit;//提交
    @Bind(R.id.tv_message)
    TextView tv_message;//提示
    @Bind(R.id.et_newpwd)
    EditText et_newpwd;//新密码
    @Bind(R.id.et_newpwd_again)
    EditText et_newpwd_again;//确认新密码

    private int time;


    @Override
    public int getLayoutId() {
        return R.layout.activity_set_paypwd;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        tv_message.setText("请为帐号" + MyApplication.getInstance().bean.getPhone().substring(0, 3) + "****" + MyApplication.getInstance().bean.getPhone().substring(7, 11)
                + "设置6位数字支付密码");
        iv_top_left.setVisibility(View.VISIBLE);
        iv_top_left.setOnClickListener(this);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("重置支付密码");
        bt_submit.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.bt_submit://提交
                if (et_newpwd.getText().toString().length() < 6 || et_newpwd_again.getText().toString().length() < 6) {
                    ToastUtils.getInstance().showToast("密码必须为6位！");
                    return;
                }
                if (!et_newpwd.getText().toString().equals(et_newpwd_again.getText().toString())) {
                    ToastUtils.getInstance().showToast("两次密码输入不同！");
                    return;
                }
                submit();
                break;
        }
    }

    private void submit() {
        OkGo.<String>post(URL.getUrl().SETPAYPWD)
                .params("m_number", MyApplication.getInstance().getUserId())
                .params("pay_password", et_newpwd.getText().toString())
                .execute(new MyStringCallBack<BaseBean>(bt_submit) {
                    @Override
                    public void onSuccessData(BaseBean bean) {
                        super.onSuccessData(bean);
                        if (bean.getCode() == 1) {
                            finish();
                        }
                        ToastUtils.getInstance().showToast(bean.getMsg());
                    }
                });
    }
}
